Skip to contentSkip to conversation

Change in openvpn[master]: win: match search domains when creating exclude rules

Openvpn-devel In review d12fk (Code Review) 2 participants 10 messages Mar 7, 2025 – May 20, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1741315174000.I4919af2b845a47787c08f454b108ef376ea5c0f6@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/905?usp=email

to review the following change.

Change subject: win: match search domains when creating exclude rules
......................................................................

win: match search domains when creating exclude rules

Compare local domains for exclude rules to search domains and skip matching ones. This prevents the creation of exclude rules when the server indicates that the domain should be resolved via the VPN, by pushing the search domain.

Change-Id I4919af2b845a47787c08f454b108ef376ea5c0f6

---
M src/openvpnserv/interactive.c

1 file changed, 56 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/905/1

src/openvpnserv/interactive.c +56 -24
index 6097cd0..f725199 100644
@@ -2163,12 +2163,14 @@
  * In case of an error or if no domains are found for the interface
  * \p size is set to 0 and the contents of \p domains are invalid.
  * Note that the domains could have been set by DHCP or manually.
+ * Note that domains are ignored if they match a pushed search domain.
  *
- * @param  itf        HKEY of the interface to read from
- * @param  domains    PWSTR buffer to return the domain(s) in
- * @param  size       pointer to size of the domains buffer in bytes. Will be
- *                    set to the size of the string returned, including
- *                    the terminating zeros or 0.
+ * @param  itf             HKEY of the interface to read from
+ * @param  search_domains  optional list of search domains
+ * @param  domains         PWSTR buffer to return the domain(s) in
+ * @param  size            pointer to size of the domains buffer in bytes. Will be
+ *                         set to the size of the string returned, including
+ *                         the terminating zeros or 0.
  *
  * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfully,
  *         ERROR_FILE_NOT_FOUND if no domain was found for the interface,
@@ -2176,7 +2178,7 @@
  *         any other error indicates an error while reading from the registry.
  */
 static LSTATUS
-GetItfDnsDomains(HKEY itf, PWSTR domains, PDWORD size)
+GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
 {
     if (domains == NULL || size == 0)
     {
@@ -2209,9 +2211,29 @@
                     *comma = '\0';
                 }
 
+                /* Ignore itf domains which match pushed search domains */
+                size_t domain_len = wcslen(pos);
+                PCWSTR match = wcsstr(search_domains, pos);
+                if (match && (match == search_domains || *(match - 1) == ',')
+                    && (*(match + domain_len) == ',' || *(match + domain_len) == '\0'))
+                {
+                    if (comma)
+                    {
+                        pos = comma + 1;
+                        continue;
+                    }
+                    else
+                    {
+                        /* This was the last domain */
+                        *pos = '\0';
+                        *size += 1;
+                        return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
+                    }
+                }
+
                 /* Check for enough space to convert this domain */
+                domain_len += 1; /* leading dot */
                 size_t converted_size = pos - domains;
-                size_t domain_len = wcslen(pos) + 1;
                 size_t domain_size = domain_len * one_glyph;
                 size_t extra_size = 2 * one_glyph;
                 if (converted_size + domain_size + extra_size > buf_size)
@@ -2292,11 +2314,12 @@
  * needed so that local DNS keeps working even when a catch all NRPT rule is
  * installed by a VPN connection.
  *
- * @param  data       pointer to the data structures the values are returned in
- * @param  data_size  number of exclude data structures pointed to
+ * @param  search_domains  optional list of search domains
+ * @param  data            pointer to the data structures the values are returned in
+ * @param  data_size       number of exclude data structures pointed to
  */
 static void
-GetNrptExcludeData(nrpt_exclude_data_t *data, size_t data_size)
+GetNrptExcludeData(PCWSTR search_domains, nrpt_exclude_data_t *data, size_t data_size)
 {
     HKEY v4_itfs = INVALID_HANDLE_VALUE;
     HKEY v6_itfs = INVALID_HANDLE_VALUE;
@@ -2342,7 +2365,7 @@
         /* Get the DNS domain(s) for exclude routing */
         data[i].domains_size = sizeof(data[0].domains);
         memset(data[i].domains, 0, data[i].domains_size);
-        err = GetItfDnsDomains(v4_itf, data[i].domains, &data[i].domains_size);
+        err = GetItfDnsDomains(v4_itf, search_domains, data[i].domains, &data[i].domains_size);
         if (err)
         {
             if (err != ERROR_FILE_NOT_FOUND)
@@ -2504,15 +2527,16 @@
  * local resolution of names is not interfered with in case the VPN resolves
  * all names.
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key        the registry key to set the rules under
+ * @param  ovpn_pid        the PID of the openvpn process
+ * @param  search_domains  optional list of search domains
  */
 static void
-SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid)
+SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid, PCWSTR search_domains)
 {
     nrpt_exclude_data_t data[8]; /* data from up to 8 interfaces */
     memset(data, 0, sizeof(data));
-    GetNrptExcludeData(data, _countof(data));
+    GetNrptExcludeData(search_domains, data, _countof(data));
 
     unsigned n = 0;
     for (int i = 0; i < _countof(data); ++i)
@@ -2534,17 +2558,18 @@
 /**
  * Set NRPT rules for a openvpn process
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  addresses  name server addresses
- * @param  domains    optional list of split routing domains
- * @param  dnssec     boolean whether DNSSEC is to be used
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key          the registry key to set the rules under
+ * @param  addresses         name server addresses
+ * @param  domains           optional list of split routing domains
+ * @param  search_domains    optional list of search domains
+ * @param  dnssec            boolean whether DNSSEC is to be used
+ * @param  ovpn_pid          the PID of the openvpn process
  *
  * @return NO_ERROR on success, or a Windows error code
  */
 static DWORD
-SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses,
-             const char *domains, BOOL dnssec, DWORD ovpn_pid)
+SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses, const char *domains,
+             const char *search_domains, BOOL dnssec, DWORD ovpn_pid)
 {
     DWORD err = NO_ERROR;
     PWSTR wide_domains = L".\0"; /* DNS route everything by default */
@@ -2573,7 +2598,14 @@
     }
     else
     {
-        SetNrptExcludeRules(nrpt_key, ovpn_pid);
+        PWSTR wide_search_domains;
+        wide_search_domains = utf8to16(search_domains);
+        if (!wide_search_domains)
+        {
+            return ERROR_OUTOFMEMORY;
+        }
+        SetNrptExcludeRules(nrpt_key, ovpn_pid, wide_search_domains);
+        free(wide_search_domains);
     }
 
     /* Create address string list */
@@ -2833,7 +2865,7 @@
 
     /* Set NRPT rules */
     BOOL dnssec = (msg->flags & nrpt_dnssec) != 0;
-    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, dnssec, ovpn_pid);
+    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->search_domains, dnssec, ovpn_pid);
     if (err)
     {
         goto out;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

d12fk has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/905?usp=email )

Change subject: win: match search domains when creating exclude rules
......................................................................

Patch Set 2:

(1 comment)

File src/openvpnserv/interactive.c:

http://gerrit.openvpn.net/c/openvpn/+/905/comment/d70b6712_811e8c80 :
PS2, Line 2218: if (match && (match == search_domains || *(match - 1) == ',')
The code doesn't deal with partial matches in the list, before a full match could be made. Instead of repeating the search from the point of the partial match, it gives up the search.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 13 Mar 2025 03:27:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/905?usp=email

to look at the new patch set (#3).

Change subject: win: match search domains when creating exclude rules
......................................................................

win: match search domains when creating exclude rules

Compare local domains for exclude rules to search domains and skip matching ones. This prevents the creation of exclude rules when the server indicates that the domain should be resolved via the VPN, by pushing the search domain.

Change-Id I4919af2b845a47787c08f454b108ef376ea5c0f6

---
M src/openvpnserv/interactive.c

1 file changed, 86 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/905/3

src/openvpnserv/interactive.c +86 -24
index 284ce15..eb3c867 100644
@@ -2158,18 +2158,52 @@
 }
 
 /**
+ * Check if a domain is contained in a comma separated list of domains
+ *
+ * @param list      Comma separated list of domains
+ * @param domain    Domain string to search for
+ * @param len       Length of the domain string, excluding the '\0'
+ *
+ * @return TRUE when the domain was found in the list, FALSE otherwise.
+ */
+static BOOL
+ListContainsDomain(PCWSTR list, PCWSTR domain, size_t len)
+{
+    PCWSTR match = list;
+    while (TRUE)
+    {
+        match = wcsstr(match, domain);
+        if (!match)
+        {
+            /* Domain has not matched */
+            break;
+        }
+        if ((match == list || *(match - 1) == ',')
+            && (*(match + len) == ',' || *(match + len) == '\0'))
+        {
+            /* Domain has matched fully */
+            return TRUE;
+        }
+        match += len;
+    }
+    return FALSE;
+}
+
+/**
  * Return interface specific domain suffix(es)
  *
  * The \p domains paramter will be set to a MULTI_SZ domains string.
  * In case of an error or if no domains are found for the interface
  * \p size is set to 0 and the contents of \p domains are invalid.
  * Note that the domains could have been set by DHCP or manually.
+ * Note that domains are ignored if they match a pushed search domain.
  *
- * @param  itf        HKEY of the interface to read from
- * @param  domains    PWSTR buffer to return the domain(s) in
- * @param  size       pointer to size of the domains buffer in bytes. Will be
- *                    set to the size of the string returned, including
- *                    the terminating zeros or 0.
+ * @param  itf             HKEY of the interface to read from
+ * @param  search_domains  optional list of search domains
+ * @param  domains         PWSTR buffer to return the domain(s) in
+ * @param  size            pointer to size of the domains buffer in bytes. Will be
+ *                         set to the size of the string returned, including
+ *                         the terminating zeros or 0.
  *
  * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfully,
  *         ERROR_FILE_NOT_FOUND if no domain was found for the interface,
@@ -2177,7 +2211,7 @@
  *         any other error indicates an error while reading from the registry.
  */
 static LSTATUS
-GetItfDnsDomains(HKEY itf, PWSTR domains, PDWORD size)
+GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
 {
     if (domains == NULL || size == 0)
     {
@@ -2210,9 +2244,27 @@
                     *comma = '\0';
                 }
 
+                /* Ignore itf domains which match a pushed search domain */
+                size_t domain_len = wcslen(pos);
+                if (ListContainsDomain(search_domains, pos, domain_len))
+                {
+                    if (comma)
+                    {
+                        pos = comma + 1;
+                        continue;
+                    }
+                    else
+                    {
+                        /* This was the last domain */
+                        *pos = '\0';
+                        *size += 1;
+                        return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
+                    }
+                }
+
                 /* Check for enough space to convert this domain */
+                domain_len += 1; /* leading dot */
                 size_t converted_size = pos - domains;
-                size_t domain_len = wcslen(pos) + 1;
                 size_t domain_size = domain_len * one_glyph;
                 size_t extra_size = 2 * one_glyph;
                 if (converted_size + domain_size + extra_size > buf_size)
@@ -2293,11 +2345,12 @@
  * needed so that local DNS keeps working even when a catch all NRPT rule is
  * installed by a VPN connection.
  *
- * @param  data       pointer to the data structures the values are returned in
- * @param  data_size  number of exclude data structures pointed to
+ * @param  search_domains  optional list of search domains
+ * @param  data            pointer to the data structures the values are returned in
+ * @param  data_size       number of exclude data structures pointed to
  */
 static void
-GetNrptExcludeData(nrpt_exclude_data_t *data, size_t data_size)
+GetNrptExcludeData(PCWSTR search_domains, nrpt_exclude_data_t *data, size_t data_size)
 {
     HKEY v4_itfs = INVALID_HANDLE_VALUE;
     HKEY v6_itfs = INVALID_HANDLE_VALUE;
@@ -2343,7 +2396,7 @@
         /* Get the DNS domain(s) for exclude routing */
         data[i].domains_size = sizeof(data[0].domains);
         memset(data[i].domains, 0, data[i].domains_size);
-        err = GetItfDnsDomains(v4_itf, data[i].domains, &data[i].domains_size);
+        err = GetItfDnsDomains(v4_itf, search_domains, data[i].domains, &data[i].domains_size);
         if (err)
         {
             if (err != ERROR_FILE_NOT_FOUND)
@@ -2505,15 +2558,16 @@
  * local resolution of names is not interfered with in case the VPN resolves
  * all names.
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key        the registry key to set the rules under
+ * @param  ovpn_pid        the PID of the openvpn process
+ * @param  search_domains  optional list of search domains
  */
 static void
-SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid)
+SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid, PCWSTR search_domains)
 {
     nrpt_exclude_data_t data[8]; /* data from up to 8 interfaces */
     memset(data, 0, sizeof(data));
-    GetNrptExcludeData(data, _countof(data));
+    GetNrptExcludeData(search_domains, data, _countof(data));
 
     unsigned n = 0;
     for (int i = 0; i < _countof(data); ++i)
@@ -2535,17 +2589,18 @@
 /**
  * Set NRPT rules for a openvpn process
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  addresses  name server addresses
- * @param  domains    optional list of split routing domains
- * @param  dnssec     boolean whether DNSSEC is to be used
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key          the registry key to set the rules under
+ * @param  addresses         name server addresses
+ * @param  domains           optional list of split routing domains
+ * @param  search_domains    optional list of search domains
+ * @param  dnssec            boolean whether DNSSEC is to be used
+ * @param  ovpn_pid          the PID of the openvpn process
  *
  * @return NO_ERROR on success, or a Windows error code
  */
 static DWORD
-SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses,
-             const char *domains, BOOL dnssec, DWORD ovpn_pid)
+SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses, const char *domains,
+             const char *search_domains, BOOL dnssec, DWORD ovpn_pid)
 {
     DWORD err = NO_ERROR;
     PWSTR wide_domains = L".\0"; /* DNS route everything by default */
@@ -2574,7 +2629,14 @@
     }
     else
     {
-        SetNrptExcludeRules(nrpt_key, ovpn_pid);
+        PWSTR wide_search_domains;
+        wide_search_domains = utf8to16(search_domains);
+        if (!wide_search_domains)
+        {
+            return ERROR_OUTOFMEMORY;
+        }
+        SetNrptExcludeRules(nrpt_key, ovpn_pid, wide_search_domains);
+        free(wide_search_domains);
     }
 
     /* Create address string list */
@@ -2834,7 +2896,7 @@
 
     /* Set NRPT rules */
     BOOL dnssec = (msg->flags & nrpt_dnssec) != 0;
-    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, dnssec, ovpn_pid);
+    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->search_domains, dnssec, ovpn_pid);
     if (err)
     {
         goto out;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

d12fk has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/905?usp=email )

Change subject: win: match search domains when creating exclude rules
......................................................................

Patch Set 3:

(1 comment)

File src/openvpnserv/interactive.c:

http://gerrit.openvpn.net/c/openvpn/+/905/comment/90f6b889_929da8d7 :
PS2, Line 2218: if (match && (match == search_domains || *(match - 1) == ',')

Quoted 1 line

The code doesn't deal with partial matches in the list, before a full match could be made. […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 14 Mar 2025 04:23:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: d12fk <[email protected]...>
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos.

stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/905?usp=email )

Change subject: win: match search domains when creating exclude rules
......................................................................

Patch Set 20: Code-Review-1

(1 comment)

Patchset:

PS20:
Let's wait before https://github.com/OpenVPN/openvpn/issues/747 is resolved.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 20
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Mon, 19 May 2025 14:55:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos.

stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/905?usp=email )

Change subject: win: match search domains when creating exclude rules
......................................................................

Patch Set 20: Code-Review+2

(1 comment)

Patchset:

PS20:
With #1005, this works as expected - when server pushes

push "dns search-domains panoulu.local"
push "dns server 1 address 1.1.1.1"

and "panoulu.local" is a connection-specific suffix in, say, Wi-Fi adapter, we do not create an exclusion rule for panoulu.local.

This has revealed an issue with SearchList implementation, but this is out of scope of this change.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 20
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Tue, 20 May 2025 10:35:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#7 lore raw

PATCH v20 1/1 win: match search domains when creating exclude rules

In reply to a message not in the archive

From: Heiko Hund <[email protected]...>

Compare local domains for exclude rules to search domains and skip matching ones. This prevents the creation of exclude rules when the server indicates that the domain should be resolved via the VPN, by pushing the search domain.

Change-Id I4919af2b845a47787c08f454b108ef376ea5c0f6

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/905
This mail reflects revision 20 of this Change.

Acked-by according to Gerrit (reflected above):
Lev Stipakov <[email protected]...>

src/openvpnserv/interactive.c +86 -24
index 5f842bd..a1581a6 100644
@@ -2126,18 +2126,52 @@
 }
 
 /**
+ * Check if a domain is contained in a comma separated list of domains
+ *
+ * @param list      Comma separated list of domains
+ * @param domain    Domain string to search for
+ * @param len       Length of the domain string, excluding the '\0'
+ *
+ * @return TRUE when the domain was found in the list, FALSE otherwise.
+ */
+static BOOL
+ListContainsDomain(PCWSTR list, PCWSTR domain, size_t len)
+{
+    PCWSTR match = list;
+    while (TRUE)
+    {
+        match = wcsstr(match, domain);
+        if (!match)
+        {
+            /* Domain has not matched */
+            break;
+        }
+        if ((match == list || *(match - 1) == ',')
+            && (*(match + len) == ',' || *(match + len) == '\0'))
+        {
+            /* Domain has matched fully */
+            return TRUE;
+        }
+        match += len;
+    }
+    return FALSE;
+}
+
+/**
  * Return interface specific domain suffix(es)
  *
  * The \p domains paramter will be set to a MULTI_SZ domains string.
  * In case of an error or if no domains are found for the interface
  * \p size is set to 0 and the contents of \p domains are invalid.
  * Note that the domains could have been set by DHCP or manually.
+ * Note that domains are ignored if they match a pushed search domain.
  *
- * @param  itf        HKEY of the interface to read from
- * @param  domains    PWSTR buffer to return the domain(s) in
- * @param  size       pointer to size of the domains buffer in bytes. Will be
- *                    set to the size of the string returned, including
- *                    the terminating zeros or 0.
+ * @param  itf             HKEY of the interface to read from
+ * @param  search_domains  optional list of search domains
+ * @param  domains         PWSTR buffer to return the domain(s) in
+ * @param  size            pointer to size of the domains buffer in bytes. Will be
+ *                         set to the size of the string returned, including
+ *                         the terminating zeros or 0.
  *
  * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfully,
  *         ERROR_FILE_NOT_FOUND if no domain was found for the interface,
@@ -2145,7 +2179,7 @@
  *         any other error indicates an error while reading from the registry.
  */
 static LSTATUS
-GetItfDnsDomains(HKEY itf, PWSTR domains, PDWORD size)
+GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
 {
     if (domains == NULL || size == 0)
     {
@@ -2179,9 +2213,27 @@
                     *comma = '\0';
                 }
 
+                /* Ignore itf domains which match a pushed search domain */
+                size_t domain_len = wcslen(pos);
+                if (ListContainsDomain(search_domains, pos, domain_len))
+                {
+                    if (comma)
+                    {
+                        pos = comma + 1;
+                        continue;
+                    }
+                    else
+                    {
+                        /* This was the last domain */
+                        *pos = '\0';
+                        *size += 1;
+                        return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
+                    }
+                }
+
                 /* Check for enough space to convert this domain */
+                domain_len += 1; /* leading dot */
                 size_t converted_size = pos - domains;
-                size_t domain_len = wcslen(pos) + 1;
                 size_t domain_size = domain_len * one_glyph;
                 size_t extra_size = 2 * one_glyph;
                 if (converted_size + domain_size + extra_size > buf_size)
@@ -2265,11 +2317,12 @@
  * needed so that local DNS keeps working even when a catch all NRPT rule is
  * installed by a VPN connection.
  *
- * @param  data       pointer to the data structures the values are returned in
- * @param  data_size  number of exclude data structures pointed to
+ * @param  search_domains  optional list of search domains
+ * @param  data            pointer to the data structures the values are returned in
+ * @param  data_size       number of exclude data structures pointed to
  */
 static void
-GetNrptExcludeData(nrpt_exclude_data_t *data, size_t data_size)
+GetNrptExcludeData(PCWSTR search_domains, nrpt_exclude_data_t *data, size_t data_size)
 {
     HKEY v4_itfs = INVALID_HANDLE_VALUE;
     HKEY v6_itfs = INVALID_HANDLE_VALUE;
@@ -2313,7 +2366,7 @@
         /* Get the DNS domain(s) for exclude routing */
         data[i].domains_size = sizeof(data[0].domains);
         memset(data[i].domains, 0, data[i].domains_size);
-        err = GetItfDnsDomains(v4_itf, data[i].domains, &data[i].domains_size);
+        err = GetItfDnsDomains(v4_itf, search_domains, data[i].domains, &data[i].domains_size);
         if (err)
         {
             if (err != ERROR_FILE_NOT_FOUND)
@@ -2471,15 +2524,16 @@
  * local resolution of names is not interfered with in case the VPN resolves
  * all names.
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key        the registry key to set the rules under
+ * @param  ovpn_pid        the PID of the openvpn process
+ * @param  search_domains  optional list of search domains
  */
 static void
-SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid)
+SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid, PCWSTR search_domains)
 {
     nrpt_exclude_data_t data[8]; /* data from up to 8 interfaces */
     memset(data, 0, sizeof(data));
-    GetNrptExcludeData(data, _countof(data));
+    GetNrptExcludeData(search_domains, data, _countof(data));
 
     unsigned n = 0;
     for (int i = 0; i < _countof(data); ++i)
@@ -2504,17 +2558,18 @@
 /**
  * Set NRPT rules for a openvpn process
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  addresses  name server addresses
- * @param  domains    optional list of split routing domains
- * @param  dnssec     boolean whether DNSSEC is to be used
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key          the registry key to set the rules under
+ * @param  addresses         name server addresses
+ * @param  domains           optional list of split routing domains
+ * @param  search_domains    optional list of search domains
+ * @param  dnssec            boolean whether DNSSEC is to be used
+ * @param  ovpn_pid          the PID of the openvpn process
  *
  * @return NO_ERROR on success, or a Windows error code
  */
 static DWORD
-SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses,
-             const char *domains, BOOL dnssec, DWORD ovpn_pid)
+SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses, const char *domains,
+             const char *search_domains, BOOL dnssec, DWORD ovpn_pid)
 {
     DWORD err = NO_ERROR;
     PWSTR wide_domains = L".\0"; /* DNS route everything by default */
@@ -2543,7 +2598,14 @@
     }
     else
     {
-        SetNrptExcludeRules(nrpt_key, ovpn_pid);
+        PWSTR wide_search_domains;
+        wide_search_domains = utf8to16(search_domains);
+        if (!wide_search_domains)
+        {
+            return ERROR_OUTOFMEMORY;
+        }
+        SetNrptExcludeRules(nrpt_key, ovpn_pid, wide_search_domains);
+        free(wide_search_domains);
     }
 
     /* Create address string list */
@@ -2803,7 +2865,7 @@
 
     /* Set NRPT rules */
     BOOL dnssec = (msg->flags & nrpt_dnssec) != 0;
-    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, dnssec, ovpn_pid);
+    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->search_domains, dnssec, ovpn_pid);
     if (err)
     {
         goto out;
#8 lore raw

[Openvpn-devel] [PATCH applied] Re: win: match search domains when creating exclude rules

Looks generally reasonable. Lev has tested this thoroughly and confirms it works :-) - there is a bug in string length calculation in here (wide/normal string) so the code as it stands does not work correctly for multiple domains. To be fixed in the next patch (#1028).

I have only compile tested this (ubuntu+mingw).

Your patch has been applied to the master branch.

commit dcc2385c033ac5df98968aad6899ddc8c4d2240e

Author: Heiko Hund
Date:   Tue May 20 12:51:12 2025 +0200
     win: match search domains when creating exclude rules

     Signed-off-by: Heiko Hund <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg31731.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#9 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#21) to the change originally created by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/905?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by stipa

Change subject: win: match search domains when creating exclude rules
......................................................................

win: match search domains when creating exclude rules

Compare local domains for exclude rules to search domains and skip matching ones. This prevents the creation of exclude rules when the server indicates that the domain should be resolved via the VPN, by pushing the search domain.

Change-Id I4919af2b845a47787c08f454b108ef376ea5c0f6

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31731.html

---
M src/openvpnserv/interactive.c

1 file changed, 86 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/905/21

src/openvpnserv/interactive.c +86 -24
index 5f842bd..a1581a6 100644
@@ -2126,18 +2126,52 @@
 }
 
 /**
+ * Check if a domain is contained in a comma separated list of domains
+ *
+ * @param list      Comma separated list of domains
+ * @param domain    Domain string to search for
+ * @param len       Length of the domain string, excluding the '\0'
+ *
+ * @return TRUE when the domain was found in the list, FALSE otherwise.
+ */
+static BOOL
+ListContainsDomain(PCWSTR list, PCWSTR domain, size_t len)
+{
+    PCWSTR match = list;
+    while (TRUE)
+    {
+        match = wcsstr(match, domain);
+        if (!match)
+        {
+            /* Domain has not matched */
+            break;
+        }
+        if ((match == list || *(match - 1) == ',')
+            && (*(match + len) == ',' || *(match + len) == '\0'))
+        {
+            /* Domain has matched fully */
+            return TRUE;
+        }
+        match += len;
+    }
+    return FALSE;
+}
+
+/**
  * Return interface specific domain suffix(es)
  *
  * The \p domains paramter will be set to a MULTI_SZ domains string.
  * In case of an error or if no domains are found for the interface
  * \p size is set to 0 and the contents of \p domains are invalid.
  * Note that the domains could have been set by DHCP or manually.
+ * Note that domains are ignored if they match a pushed search domain.
  *
- * @param  itf        HKEY of the interface to read from
- * @param  domains    PWSTR buffer to return the domain(s) in
- * @param  size       pointer to size of the domains buffer in bytes. Will be
- *                    set to the size of the string returned, including
- *                    the terminating zeros or 0.
+ * @param  itf             HKEY of the interface to read from
+ * @param  search_domains  optional list of search domains
+ * @param  domains         PWSTR buffer to return the domain(s) in
+ * @param  size            pointer to size of the domains buffer in bytes. Will be
+ *                         set to the size of the string returned, including
+ *                         the terminating zeros or 0.
  *
  * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfully,
  *         ERROR_FILE_NOT_FOUND if no domain was found for the interface,
@@ -2145,7 +2179,7 @@
  *         any other error indicates an error while reading from the registry.
  */
 static LSTATUS
-GetItfDnsDomains(HKEY itf, PWSTR domains, PDWORD size)
+GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
 {
     if (domains == NULL || size == 0)
     {
@@ -2179,9 +2213,27 @@
                     *comma = '\0';
                 }
 
+                /* Ignore itf domains which match a pushed search domain */
+                size_t domain_len = wcslen(pos);
+                if (ListContainsDomain(search_domains, pos, domain_len))
+                {
+                    if (comma)
+                    {
+                        pos = comma + 1;
+                        continue;
+                    }
+                    else
+                    {
+                        /* This was the last domain */
+                        *pos = '\0';
+                        *size += 1;
+                        return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
+                    }
+                }
+
                 /* Check for enough space to convert this domain */
+                domain_len += 1; /* leading dot */
                 size_t converted_size = pos - domains;
-                size_t domain_len = wcslen(pos) + 1;
                 size_t domain_size = domain_len * one_glyph;
                 size_t extra_size = 2 * one_glyph;
                 if (converted_size + domain_size + extra_size > buf_size)
@@ -2265,11 +2317,12 @@
  * needed so that local DNS keeps working even when a catch all NRPT rule is
  * installed by a VPN connection.
  *
- * @param  data       pointer to the data structures the values are returned in
- * @param  data_size  number of exclude data structures pointed to
+ * @param  search_domains  optional list of search domains
+ * @param  data            pointer to the data structures the values are returned in
+ * @param  data_size       number of exclude data structures pointed to
  */
 static void
-GetNrptExcludeData(nrpt_exclude_data_t *data, size_t data_size)
+GetNrptExcludeData(PCWSTR search_domains, nrpt_exclude_data_t *data, size_t data_size)
 {
     HKEY v4_itfs = INVALID_HANDLE_VALUE;
     HKEY v6_itfs = INVALID_HANDLE_VALUE;
@@ -2313,7 +2366,7 @@
         /* Get the DNS domain(s) for exclude routing */
         data[i].domains_size = sizeof(data[0].domains);
         memset(data[i].domains, 0, data[i].domains_size);
-        err = GetItfDnsDomains(v4_itf, data[i].domains, &data[i].domains_size);
+        err = GetItfDnsDomains(v4_itf, search_domains, data[i].domains, &data[i].domains_size);
         if (err)
         {
             if (err != ERROR_FILE_NOT_FOUND)
@@ -2471,15 +2524,16 @@
  * local resolution of names is not interfered with in case the VPN resolves
  * all names.
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key        the registry key to set the rules under
+ * @param  ovpn_pid        the PID of the openvpn process
+ * @param  search_domains  optional list of search domains
  */
 static void
-SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid)
+SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid, PCWSTR search_domains)
 {
     nrpt_exclude_data_t data[8]; /* data from up to 8 interfaces */
     memset(data, 0, sizeof(data));
-    GetNrptExcludeData(data, _countof(data));
+    GetNrptExcludeData(search_domains, data, _countof(data));
 
     unsigned n = 0;
     for (int i = 0; i < _countof(data); ++i)
@@ -2504,17 +2558,18 @@
 /**
  * Set NRPT rules for a openvpn process
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  addresses  name server addresses
- * @param  domains    optional list of split routing domains
- * @param  dnssec     boolean whether DNSSEC is to be used
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key          the registry key to set the rules under
+ * @param  addresses         name server addresses
+ * @param  domains           optional list of split routing domains
+ * @param  search_domains    optional list of search domains
+ * @param  dnssec            boolean whether DNSSEC is to be used
+ * @param  ovpn_pid          the PID of the openvpn process
  *
  * @return NO_ERROR on success, or a Windows error code
  */
 static DWORD
-SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses,
-             const char *domains, BOOL dnssec, DWORD ovpn_pid)
+SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses, const char *domains,
+             const char *search_domains, BOOL dnssec, DWORD ovpn_pid)
 {
     DWORD err = NO_ERROR;
     PWSTR wide_domains = L".\0"; /* DNS route everything by default */
@@ -2543,7 +2598,14 @@
     }
     else
     {
-        SetNrptExcludeRules(nrpt_key, ovpn_pid);
+        PWSTR wide_search_domains;
+        wide_search_domains = utf8to16(search_domains);
+        if (!wide_search_domains)
+        {
+            return ERROR_OUTOFMEMORY;
+        }
+        SetNrptExcludeRules(nrpt_key, ovpn_pid, wide_search_domains);
+        free(wide_search_domains);
     }
 
     /* Create address string list */
@@ -2803,7 +2865,7 @@
 
     /* Set NRPT rules */
     BOOL dnssec = (msg->flags & nrpt_dnssec) != 0;
-    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, dnssec, ovpn_pid);
+    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->search_domains, dnssec, ovpn_pid);
     if (err)
     {
         goto out;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 21
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#10 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/905?usp=email )

Change subject: win: match search domains when creating exclude rules
......................................................................

win: match search domains when creating exclude rules

Compare local domains for exclude rules to search domains and skip matching ones. This prevents the creation of exclude rules when the server indicates that the domain should be resolved via the VPN, by pushing the search domain.

Change-Id I4919af2b845a47787c08f454b108ef376ea5c0f6

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31731.html

---
M src/openvpnserv/interactive.c

1 file changed, 86 insertions(+), 24 deletions(-)
src/openvpnserv/interactive.c +86 -24
index 5f842bd..a1581a6 100644
@@ -2126,18 +2126,52 @@
 }
 
 /**
+ * Check if a domain is contained in a comma separated list of domains
+ *
+ * @param list      Comma separated list of domains
+ * @param domain    Domain string to search for
+ * @param len       Length of the domain string, excluding the '\0'
+ *
+ * @return TRUE when the domain was found in the list, FALSE otherwise.
+ */
+static BOOL
+ListContainsDomain(PCWSTR list, PCWSTR domain, size_t len)
+{
+    PCWSTR match = list;
+    while (TRUE)
+    {
+        match = wcsstr(match, domain);
+        if (!match)
+        {
+            /* Domain has not matched */
+            break;
+        }
+        if ((match == list || *(match - 1) == ',')
+            && (*(match + len) == ',' || *(match + len) == '\0'))
+        {
+            /* Domain has matched fully */
+            return TRUE;
+        }
+        match += len;
+    }
+    return FALSE;
+}
+
+/**
  * Return interface specific domain suffix(es)
  *
  * The \p domains paramter will be set to a MULTI_SZ domains string.
  * In case of an error or if no domains are found for the interface
  * \p size is set to 0 and the contents of \p domains are invalid.
  * Note that the domains could have been set by DHCP or manually.
+ * Note that domains are ignored if they match a pushed search domain.
  *
- * @param  itf        HKEY of the interface to read from
- * @param  domains    PWSTR buffer to return the domain(s) in
- * @param  size       pointer to size of the domains buffer in bytes. Will be
- *                    set to the size of the string returned, including
- *                    the terminating zeros or 0.
+ * @param  itf             HKEY of the interface to read from
+ * @param  search_domains  optional list of search domains
+ * @param  domains         PWSTR buffer to return the domain(s) in
+ * @param  size            pointer to size of the domains buffer in bytes. Will be
+ *                         set to the size of the string returned, including
+ *                         the terminating zeros or 0.
  *
  * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfully,
  *         ERROR_FILE_NOT_FOUND if no domain was found for the interface,
@@ -2145,7 +2179,7 @@
  *         any other error indicates an error while reading from the registry.
  */
 static LSTATUS
-GetItfDnsDomains(HKEY itf, PWSTR domains, PDWORD size)
+GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
 {
     if (domains == NULL || size == 0)
     {
@@ -2179,9 +2213,27 @@
                     *comma = '\0';
                 }
 
+                /* Ignore itf domains which match a pushed search domain */
+                size_t domain_len = wcslen(pos);
+                if (ListContainsDomain(search_domains, pos, domain_len))
+                {
+                    if (comma)
+                    {
+                        pos = comma + 1;
+                        continue;
+                    }
+                    else
+                    {
+                        /* This was the last domain */
+                        *pos = '\0';
+                        *size += 1;
+                        return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
+                    }
+                }
+
                 /* Check for enough space to convert this domain */
+                domain_len += 1; /* leading dot */
                 size_t converted_size = pos - domains;
-                size_t domain_len = wcslen(pos) + 1;
                 size_t domain_size = domain_len * one_glyph;
                 size_t extra_size = 2 * one_glyph;
                 if (converted_size + domain_size + extra_size > buf_size)
@@ -2265,11 +2317,12 @@
  * needed so that local DNS keeps working even when a catch all NRPT rule is
  * installed by a VPN connection.
  *
- * @param  data       pointer to the data structures the values are returned in
- * @param  data_size  number of exclude data structures pointed to
+ * @param  search_domains  optional list of search domains
+ * @param  data            pointer to the data structures the values are returned in
+ * @param  data_size       number of exclude data structures pointed to
  */
 static void
-GetNrptExcludeData(nrpt_exclude_data_t *data, size_t data_size)
+GetNrptExcludeData(PCWSTR search_domains, nrpt_exclude_data_t *data, size_t data_size)
 {
     HKEY v4_itfs = INVALID_HANDLE_VALUE;
     HKEY v6_itfs = INVALID_HANDLE_VALUE;
@@ -2313,7 +2366,7 @@
         /* Get the DNS domain(s) for exclude routing */
         data[i].domains_size = sizeof(data[0].domains);
         memset(data[i].domains, 0, data[i].domains_size);
-        err = GetItfDnsDomains(v4_itf, data[i].domains, &data[i].domains_size);
+        err = GetItfDnsDomains(v4_itf, search_domains, data[i].domains, &data[i].domains_size);
         if (err)
         {
             if (err != ERROR_FILE_NOT_FOUND)
@@ -2471,15 +2524,16 @@
  * local resolution of names is not interfered with in case the VPN resolves
  * all names.
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key        the registry key to set the rules under
+ * @param  ovpn_pid        the PID of the openvpn process
+ * @param  search_domains  optional list of search domains
  */
 static void
-SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid)
+SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid, PCWSTR search_domains)
 {
     nrpt_exclude_data_t data[8]; /* data from up to 8 interfaces */
     memset(data, 0, sizeof(data));
-    GetNrptExcludeData(data, _countof(data));
+    GetNrptExcludeData(search_domains, data, _countof(data));
 
     unsigned n = 0;
     for (int i = 0; i < _countof(data); ++i)
@@ -2504,17 +2558,18 @@
 /**
  * Set NRPT rules for a openvpn process
  *
- * @param  nrpt_key   the registry key to set the rules under
- * @param  addresses  name server addresses
- * @param  domains    optional list of split routing domains
- * @param  dnssec     boolean whether DNSSEC is to be used
- * @param  ovpn_pid   the PID of the openvpn process
+ * @param  nrpt_key          the registry key to set the rules under
+ * @param  addresses         name server addresses
+ * @param  domains           optional list of split routing domains
+ * @param  search_domains    optional list of search domains
+ * @param  dnssec            boolean whether DNSSEC is to be used
+ * @param  ovpn_pid          the PID of the openvpn process
  *
  * @return NO_ERROR on success, or a Windows error code
  */
 static DWORD
-SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses,
-             const char *domains, BOOL dnssec, DWORD ovpn_pid)
+SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses, const char *domains,
+             const char *search_domains, BOOL dnssec, DWORD ovpn_pid)
 {
     DWORD err = NO_ERROR;
     PWSTR wide_domains = L".\0"; /* DNS route everything by default */
@@ -2543,7 +2598,14 @@
     }
     else
     {
-        SetNrptExcludeRules(nrpt_key, ovpn_pid);
+        PWSTR wide_search_domains;
+        wide_search_domains = utf8to16(search_domains);
+        if (!wide_search_domains)
+        {
+            return ERROR_OUTOFMEMORY;
+        }
+        SetNrptExcludeRules(nrpt_key, ovpn_pid, wide_search_domains);
+        free(wide_search_domains);
     }
 
     /* Create address string list */
@@ -2803,7 +2865,7 @@
 
     /* Set NRPT rules */
     BOOL dnssec = (msg->flags & nrpt_dnssec) != 0;
-    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, dnssec, ovpn_pid);
+    err = SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->search_domains, dnssec, ovpn_pid);
     if (err)
     {
         goto out;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 21
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged